﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DiscoveryLogic.Analytics.Modules.Entities
{
    /// <summary>
    /// Interaction logic for PersonTreeView.xaml
    /// </summary>
    public partial class PersonTreeView : UserControl
    {
        #region event
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataSetName"></param>
        public delegate void OnPersonDataSetSelected(string dataSetName);

        public event OnPersonDataSetSelected PersonDataSetSelected;
        #endregion

        #region fields
        private PersonTreePresenter _Presenter;
        #endregion

        #region ctor
        public PersonTreeView()
        {
            InitializeComponent();
        }

        public PersonTreeView(PersonTreePresenter presneter)
			: this()
		{
			_Presenter = presneter;
			_Presenter.View = this;
		}
        #endregion

        #region populate 
        public void PopulateTreeView(List<string> personDataSetNames)
        {
            this.treePersons.DataContext = personDataSetNames;
        }
        #endregion

        #region selection
        private void treePersons_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeViewItem selectedTreeItem = e.NewValue as TreeViewItem;
            string dataSetName =(string) selectedTreeItem.Header;
            if (this.PersonDataSetSelected != null)
                this.PersonDataSetSelected(dataSetName);
        }
        #endregion
    }
}
